window = global;
window._webmsxyw = function (){}

navigator = {
    platform: "Win32",
    appCodeName: "Mozilla",
    appName: "Netscape",
    appVersion: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36",
    userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
}


window.Image = function() {
    return {
        src: '',
        width: 100,
        height: 100,
        complete: true
    };
};

window.HTMLCanvasElement = {}
window.CanvasRenderingContext2D = {}

document = {
    createElement: function(ele) {
        if (ele == "canvas") {
            return {getContext: function(type) {}};
        } else if (ele == "div") {
            return {};
        }
    },
    documentElement:{},
    querySelectorAll: function(selector) {
        return [];
    },
    cookie: 'a1=1960e2acef4ev020adbqbgxdcps88phbukzabnajf50000272280; webId=4b6833e542f84e76fbfb34e006eddce8; gid=yjK8dJ0fS47WyjK8dJ0SdTI0i4dh8J80fDADuVikCfSUM028YYUxDD888JWJJY88jy8DJjDy; abRequestId=4b6833e542f84e76fbfb34e006eddce8; webBuild=4.70.2; access-token-ad.xiaohongshu.com=customer.leona.AT-68c517522291385664194259wxwdatcmj0nalkml; ads-partner-sid=4654b314944a4dbcbc9dfc7887244a5d; system.alias=ads_partner; access-token-partner.xiaohongshu.com=customer.ads_partner.AT-68c517522294611184654297yuaz0twyfmji5h0m; ares.beaker.session.id=1751444908302086821763; websectiga=9730ffafd96f2d09dc024760e253af6ab1feb0002827740b95a255ddf6847fc8; sec_poison_id=ac5cd95b-6885-4ee1-b42e-2db3e727a579; xsecappid=xhs-pc-web; loadts=1751451589701; unread={%22ub%22:%2268629f8f000000002201f520%22%2C%22ue%22:%226863d4d9000000001c031d87%22%2C%22uc%22:30}',
    __webdriver_evaluate:{}
}

localStorage = {
    getItem:function () {
        return '{"signVersion":"1"}'
    },
}

location = {
    host: 'www.xiaohongshu.com'
}


function SetProxy(proxyObjs) {
    for (let i = 0; i < proxyObjs.length; i++) {
        const handler = {
            get: function(target, property, receiver) {
                if (property != "Math" && property != "isNaN") {
                    if (target[property] && typeof target[property] != "string" && Object.keys(target[property]).length > 3) {
                        // Skip logging for complex objects with more than 3 properties
                    } else {
                        console.log("方法:", "get ", "对象:", proxyObjs[i], "属性:", property, 
                                  "属性类型:", typeof property, ", 属性值:", target[property]);
                    }
                }
                return target[property];
            },
            set: function(target, property, value, receiver) {
                console.log("方法:", "set ", "对象:", proxyObjs[i], "属性:", property, 
                            "属性类型:", typeof property, ", 属性值:", value, 
                            ", 属性值类型:", typeof target[property]);
                return Reflect.set(...arguments);
            }
        };

        try {
            // First try to evaluate the object
            const obj = eval(proxyObjs[i]);
            // Create proxy for the object
            eval(`${proxyObjs[i]} = new Proxy(obj, handler)`);
        } catch (e) {
            // If evaluation fails, create an empty object and proxy it
            eval(`${proxyObjs[i]} = {}`);
            eval(`${proxyObjs[i]} = new Proxy(${proxyObjs[i]}, handler)`);
        }
    }
}

proxyObjs = ['window', 'navigator', 'document', 'location', 'localStorage']

// 开启环境代理
SetProxy(proxyObjs);
